load("@rules_rust//rust:defs.bzl", "rust_library")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
    # Keep sorted.
    "//rs/rust_canisters/dfn_core",
    "//rs/rust_canisters/dfn_json",
    "//rs/types/management_canister_types",
    "@crate_index//:candid",
    "@crate_index//:futures",
    "@crate_index//:ic-cdk",
    "@crate_index//:rand",
    "@crate_index//:rand_pcg",
    "@crate_index//:serde",
    "@crate_index//:serde_json",
    "@crate_index//:wat",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/rust_canisters/canister_test",
    "//rs/state_machine_tests",
    "//rs/types/types",
]

MACRO_DEPENDENCIES = []

rust_library(
    name = "canister_creator",
    srcs = glob(["src/**"]),
    crate_name = "canister_creator",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.1.0",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "canister_creator_canister",
    srcs = ["src/main.rs"],
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":canister_creator.did",
    deps = DEPENDENCIES,
)

rust_ic_test(
    name = "canister_creator_integration_test",
    srcs = ["test/test.rs"],
    data = [
        ":canister_creator_canister",
    ],
    env = {
        "CARGO_MANIFEST_DIR": "rs/rust_canisters/canister_creator",
        "CANISTER_CREATOR_CANISTER_WASM_PATH": "$(rootpath //rs/rust_canisters/canister_creator:canister_creator_canister)",
    },
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)
